package org.flint92.springboot.mybatis.controller;

import org.flint92.springboot.mybatis.domain.User;
import org.flint92.springboot.mybatis.mapper.UserMapper;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author flint92
 */
@RestController
public class UserController {

    @Resource
    private UserMapper userMapper;

    @Resource
    private SqlSessionTemplate sqlSessionTemplate;

    @GetMapping("/user/{id}")
    public User selectUserById(@PathVariable(value = "id") int id) {
        return userMapper.selectUserById(id);
    }

    @GetMapping("/user")
    public User selectUserByParamId(@RequestParam(value = "id") int id) {
        String statement = "org.flint92.springboot.mybatis.mapper.UserMapper.selectUserById";
        return sqlSessionTemplate.selectOne(statement, id);
    }

}
